class Solution {
public:
    int characterReplacement(string s, int k) {
        int n = s.size();
        
        int ans = 0;
        int cnt = 0;
        int l = 0,r = 0;
        vector<int> nums(26);
        
        while(r < n){
            nums[s[r] - 'A']++;
            cnt = max(cnt,nums[s[r] - 'A']);
            if(cnt + k < r - l + 1){
                nums[s[l] - 'A']--;
                l++;
            }
            ans = max(ans,r - l + 1);
            r++;
        }
        
        return ans;
    }
};

